package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DxmKehu;
import com.ruoyi.system.service.IDxmKehuService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户管理Controller
 * 
 * @author dxm
 * @date 2024-02-28
 */
@RestController
@RequestMapping("/system/kehu")
public class DxmKehuController extends BaseController
{
    @Autowired
    private IDxmKehuService dxmKehuService;

    /**
     * 查询客户管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:kehu:list')")
    @GetMapping("/list")
    public TableDataInfo list(DxmKehu dxmKehu)
    {
        startPage();
        List<DxmKehu> list = dxmKehuService.selectDxmKehuList(dxmKehu);
        return getDataTable(list);
    }

    /**
     * 导出客户管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:kehu:export')")
    @Log(title = "客户管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DxmKehu dxmKehu)
    {
        List<DxmKehu> list = dxmKehuService.selectDxmKehuList(dxmKehu);
        ExcelUtil<DxmKehu> util = new ExcelUtil<DxmKehu>(DxmKehu.class);
        util.exportExcel(response, list, "客户管理数据");
    }

    /**
     * 获取客户管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:kehu:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dxmKehuService.selectDxmKehuById(id));
    }

    /**
     * 新增客户管理
     */
    @PreAuthorize("@ss.hasPermi('system:kehu:add')")
    @Log(title = "客户管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DxmKehu dxmKehu)
    {
        return toAjax(dxmKehuService.insertDxmKehu(dxmKehu));
    }

    /**
     * 修改客户管理
     */
    @PreAuthorize("@ss.hasPermi('system:kehu:edit')")
    @Log(title = "客户管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DxmKehu dxmKehu)
    {
        return toAjax(dxmKehuService.updateDxmKehu(dxmKehu));
    }

    /**
     * 删除客户管理
     */
    @PreAuthorize("@ss.hasPermi('system:kehu:remove')")
    @Log(title = "客户管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dxmKehuService.deleteDxmKehuByIds(ids));
    }
}
